package com.ph.irp.base.verifyproject.dao.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import com.ph.irp.base.verifyproject.dao.PBaseVerifyprojectStoragetypeDao;
import com.ph.irp.model.PBaseVerifyprojectStoragetype;
import com.ph.util.DBUtil;

public class PBaseVerifyprojectStoragetypeDaoImpl implements PBaseVerifyprojectStoragetypeDao{

	private ComboPooledDataSource dataSource;
	
	public void setDataSource(ComboPooledDataSource dataSource) {
		this.dataSource = dataSource;
	}
	@Override
	public PBaseVerifyprojectStoragetype getStorageTypeById(int storageTypeId)
			throws Throwable {
		Connection con = null;
		PreparedStatement pStmt = null;
		ResultSet rs = null;
		PBaseVerifyprojectStoragetype storageType = null;
		
		StringBuilder sb = new StringBuilder();
		sb.append("select * from p_base_verifyproject_storagetype where StorageTypeID=").append(storageTypeId);
		
		try {
			con = dataSource.getConnection();
			pStmt = con.prepareStatement(sb.toString());
			rs = pStmt.executeQuery();
			if(rs.next()){
				storageType = new PBaseVerifyprojectStoragetype();
				storageType.setStorageTypeId(rs.getInt("StorageTypeID"));
				storageType.setStorageTypeCode(rs.getString("StorageTypeCode"));
				storageType.setStorageTypeName(rs.getString("StorageTypeName"));
			}
		} catch (Exception e) {
			throw new Exception(e.getMessage());
		} finally {
			try {
				DBUtil.setNullObject(con, pStmt, rs);
			} catch (Exception e) {
				throw new Exception(e.getMessage());
			}
		}
		return storageType;
	}

}
